<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ES5手写实现继承</title>
</head>
<body>
    <script>

        function Proson(name, age, height){ // 父类
            this.name = name;
            this.age = age;
            this.height = height;
        }
        const p1 = new Proson('张三', 18, 1.88);

        Proson.prototype.sayHi = function(){  // 父类的方法
            console.log('父类的sayHi');
        }
        Proson.prototype.running = function(){ // 父类的方法
            console.log('父类的running');
        }

        function Student(name, age, height, score,son){ // 子类
            Proson.call(this, name, age, height); // 使子类继承父类的属性
            this.score = score;
            this.son = son;
        }
        // 继承父类的方法
        Student.prototype = Object.create(Proson.prototype) // 继承父类的方法
        Object.defineProperty(Student.prototype, 'constructor', { // 使之构造函数指向子类 constructor
            enumerable: false,
            writable:false,
            configurable:false,
            value: Student
        })
        Student.prototype.eating = function(){ // 添加子类的方法
            console.log('eating');
        }
        console.log(Student.prototype);
        const stu1 = new Student('李四', 19, 1.77, 99, '202039070210');
        console.log(stu1);


    </script>
</body>
</html>